package cn.cqie.frame.service.impl;

import cn.cqie.frame.bo.add.AddUserReqBo;
import cn.cqie.frame.entity.UserRole;
import cn.cqie.frame.mapper.UserRoleMapper;
import cn.cqie.frame.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author XYHL
 * @since 2021-09-02
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Autowired
    UserRoleService userRoleService;

    /**
     * 插入用户的权限
     * @param bo
     * @return
     */
    @Override
    public boolean addUserRole(AddUserReqBo bo) {
        List<UserRole> userRoleList = new ArrayList<>();
        if (bo.getRoleIdList()!=null){
            bo.getRoleIdList().forEach(x ->{
                UserRole userRole = new UserRole();
                userRole.setRoleId(x);
                userRole.setUserId(bo.getUserId());
                userRoleList.add(userRole);
            });
        }
        return userRoleService.saveBatch(userRoleList);
    }
}
